<?php

/* @var $this yii\web\View */
use yii\helpers\Url;

$web = Url::base();
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="<?= $web ?>/js/jquery-1.10.2.min.js"></script>
    <script src="<?= $web ?>/js/tools.js"></script>
    <style>
        body{
           font-size: 1rem;
        }
    </style>
    <title>支付测试</title>

</head>
<body>
<script>
    function is_weixin(){
        var ua = navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i)=="micromessenger") {
            return true;
        } else {
            return false;
        }
    }
    var openid='<?=$openid?>';
    $(function($) {
        $("#btn_weixin").hide();
        $("#btn_ali").hide();
        if (is_weixin()) {
            $("#btn_weixin").show();
            if(openid==''){
                weixinpay_start();
            }
        } else {
            $("#btn_ali").show();
        }
    });
</script>
<form id="alipayment" action='<?=Url::to(["pay-integral/cash-to-integral-alipay"])?>' method='post'  >
 支付宝支付
    积分:<input  name="integral" value="<?=$integral?>" type="input"/>
    订单号:<input  name="order_code" value="<?=$order_code?>" type="input"/>
<input type="submit" value="支付宝支付" id="btn_ali">
</form>
<!--微信支付-->
<script>
    //获取openid
    weixinpay_start=function(){
        window.location.href="<?=Url::to(['pay-integral/get-weixin-auth','url'=>Url::to(['pay-integral/index','integral'=>$integral,'order_code'=>$order_code],true)])?>";
    };
    var out_trade_no='<?=$out_trade_no?>';

    function invoke_weixinPay(){
        if(openid!='') {
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
            } else {
                onBridgeReady();
            }
        }else {
            alert('没有授权公众号，重新授权获取授权');
            weixinpay_start();
        }
    }

    //支付
    onBridgeReady=function(){

        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',
            <?=$weixinpayJs?>,
            function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    alert("等待支付成功");
                    setTimeout("href_sureCart();",1000);

//                    alert(out_trade_no);
                }else{
                    window.location.href ='http://www.baidu.com'
                }
            }
        );
    };

    function href_sureCart(){
        window.location.href = 'http://www.baidu.com';
    }

</script>
<input type="button" id="btn_weixin" value="微信购买b" onclick="invoke_weixinPay();">
<a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=631513181&site=qq&menu=yes">
    <img border="0" src="http://wpa.qq.com/pa?p=2:631513181:51" alt="点击这里给我发消息" title="点击这里给我发消息"/>
</a>
</body>
</html>
